package com.jiuyun.service.impl;

import com.jiuyun.dao.ClassesDao;
import com.jiuyun.dao.impl.ClassesDaoImpl;
import com.jiuyun.entity.Homework;
import com.jiuyun.entity.Student;
import com.jiuyun.service.ClassService;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;

public class ClassServiceImpl implements ClassService {
    ClassesDao dao=new ClassesDaoImpl();
    @Override
    public HashMap<String, int[]> homework(int cid,int nian,int yue) throws SQLException {
        HashMap<String, int[]> info=new HashMap<String, int[]>();
        int days[]={30,28,31,30,31,30,31,31,30,31,30,31};
        if(nian%4==0 && nian%100!=0 || nian%400==0){
            days[1]=29;//闰年29天
        }
        int num=days[yue-1];//本月天数
        //所有学生
        List<Student> stus=dao.getStudents(cid);
        //没写作业的列
        List<Homework> works=dao.getHomework(cid,nian,yue);
        for(Student s:stus){
            info.put(s.getStname(),new int[num]);
        }

        for (Homework h:works){
            String stname=h.getStname();
            int t = h.getCtime().getDate();
            int rq[]=info.get(stname);
            rq[t-1]=1;//没做的标志
        }
        return info;
    }
}
